package com.huawei.appgallery.search.ui.card;

import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.LineImageView;
import com.huawei.appgallery.search.ui.cardbean.SearchPostItemCardBean;
import java.util.List;
import o.cgz;
import o.cuv.a;
import o.cuv.b;
import o.cuv.e;
import o.cvo;
import o.CollectCheck;
import o.eqx;

public class SearchPostItemCard extends BaseCompositeItemCard {
    private TextView ʻ;
    private LayoutInflater ʼ;
    private LinearLayout ʽ;
    private int ˋ;
    private TextView ॱॱ;
    private View ᐝ;

    public SearchPostItemCard(Context context) {
        super(context);
        this.ʼ = LayoutInflater.from(context);
    }

    public cgz ˏ(View view) {
        this.ʽ = (LinearLayout) view.findViewById(b.ꜞ);
        this.ॱॱ = (TextView) view.findViewById(b.ʿॱ);
        this.ʻ = (TextView) view.findViewById(b.ॱˊ);
        this.ᐝ = view.findViewById(b.ॱˎ);
        this.ˋ = cvo.ˊ();
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof SearchPostItemCardBean) {
            int i;
            int i2;
            SearchPostItemCardBean searchPostItemCardBean = (SearchPostItemCardBean) cardBean;
            CharSequence ˊ = searchPostItemCardBean.ˊ();
            CharSequence O_ = searchPostItemCardBean.O_();
            int i3 = !TextUtils.isEmpty(ˊ) ? 1 : 0;
            if (TextUtils.isEmpty(O_)) {
                i = 0;
            } else {
                i = 1;
            }
            TextView textView = this.ॱॱ;
            if (i3 != 0) {
                i2 = 0;
            } else {
                i2 = 8;
            }
            textView.setVisibility(i2);
            textView = this.ʻ;
            if (i != 0) {
                i2 = 0;
            } else {
                i2 = 8;
            }
            textView.setVisibility(i2);
            this.ॱॱ.setText(ˊ);
            this.ʻ.setText(O_);
            Resources resources = this.ʼॱ.getResources();
            int dimensionPixelSize = resources.getDimensionPixelSize(a.ˋ);
            LayoutParams layoutParams = (LayoutParams) this.ʽ.getLayoutParams();
            if (i3 == 0 && i == 0) {
                layoutParams.bottomMargin = dimensionPixelSize;
            } else {
                layoutParams.bottomMargin = resources.getDimensionPixelSize(a.ॱ);
            }
            layoutParams = (LayoutParams) this.ॱॱ.getLayoutParams();
            if (i != 0) {
                layoutParams.bottomMargin = resources.getDimensionPixelSize(a.ˊ);
            } else {
                layoutParams.bottomMargin = dimensionPixelSize;
            }
            ˊ(searchPostItemCardBean.ॱ());
            if (ˊ()) {
                i2 = 0;
            } else {
                i2 = this.ʼॱ.getResources().getDimensionPixelSize(a.ˋ);
            }
            this.ʽ.setPadding(this.ʽ.getPaddingLeft(), i2, this.ʽ.getPaddingRight(), this.ʽ.getPaddingBottom());
            if (ˎ()) {
                this.ᐝ.setVisibility(8);
            } else {
                this.ᐝ.setVisibility(0);
            }
        }
    }

    private void ˊ(List<String> list) {
        if (CollectCheck.isEmpty((List) list)) {
            this.ʽ.setVisibility(8);
            return;
        }
        this.ʽ.setTag(list);
        this.ʽ.removeAllViews();
        int i;
        if (list.size() >= 3) {
            int dimensionPixelSize = this.ʼॱ.getResources().getDimensionPixelSize(a.ˏॱ);
            int i2 = (this.ˋ - (dimensionPixelSize * 2)) / 3;
            int i3 = (int) (((double) i2) / 1.3333333333333333d);
            for (i = 0; i < 3; i++) {
                ImageView ˋ = ˋ();
                ViewGroup.LayoutParams layoutParams = new LayoutParams(i2, i3);
                if (i < 2) {
                    layoutParams.setMarginEnd(dimensionPixelSize);
                }
                this.ʽ.addView(ˋ, layoutParams);
                eqx.ˎ(ˋ, (String) list.get(i));
            }
            return;
        }
        i = (int) (((double) this.ˋ) / 1.7777777777777777d);
        ImageView ˋ2 = ˋ();
        this.ʽ.addView(ˋ2, new LayoutParams(this.ˋ, i));
        eqx.ˎ(ˋ2, (String) list.get(0));
    }

    private ImageView ˋ() {
        return (LineImageView) this.ʼ.inflate(e.ʽॱ, null);
    }
}
